-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kraken ws orders #349
Merged
Merged
Kraken ws orders #349
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goodboy
added
perf
efficiency and latency optimization
clearing
auction and mm tech: EMS, OMS, algo-trading
broker-backend
`brokerd`/`datad` related backend tech
labels
Jul 5, 2022
Order "edits" now fully working 🏄🏼 |
goodboy
commented
Jul 5, 2022
@@ -20,19 +20,19 @@ | |||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget this file! 😂
Merged
goodboy
force-pushed
the
kraken_ws_orders
branch
2 times, most recently
from
July 5, 2022 21:50
0459c8e
to
ff38e72
Compare
goodboy
force-pushed
the
kraken_ws_orders
branch
3 times, most recently
from
July 9, 2022 17:14
5100036
to
f649869
Compare
Pretty sure everything is mostly working. Just need to test some live clears and darks. |
goodboy
force-pushed
the
kraken_ws_orders
branch
2 times, most recently
from
July 14, 2022 13:28
db9b3c8
to
7fe5e4c
Compare
goodboy
force-pushed
the
kraken_ws_orders
branch
3 times, most recently
from
July 21, 2022 16:11
aa9ed79
to
9729066
Compare
goodboy
force-pushed
the
kraken_ws_orders
branch
from
July 21, 2022 19:32
9729066
to
2d0f926
Compare
This ended up driving the rework of the `piker.pp` apis to use context manager + table style which resulted in a much easier to follow state/update system B). Also added is a flag to do a manual simulation of a "fill triggered rt pp msg" which requires the user to delete the last ledgered trade entry from config files and then allowing that trade to emit through the `openOrders` sub and update client shortly after order mode boot; this is how the rt updates were verified to work without doing even more live orders 😂. Patch details: - open both `open_trade_ledger()` and `open_pps()` inside the trade dialog startup and conduct a "pp state sync" logic phase where we now pull the account balances and incrementally load pp data (in order, from `pps.toml`, ledger, api) until we can generate the asset balance by reverse incrementing through trade history eventually erroring out if we can't reproduce the balance value. - rework the `trade2pps()` to take in the `PpTable` and generate new ems msgs from table updates. - return the new `dict[str, Transaction]` expected from `norm_trade_records()` - only update pp config and ledger on dialog exit.
If we don't have a pos table built out already (in mem) we can't figure out the likely dst asset (since there's no pair entry to guide us) that we should use to search for withdrawal transactions; so move it later. Further this ports to the new api changes in `piker.pp`` that will land with #365.
goodboy
force-pushed
the
kraken_ws_orders
branch
from
July 30, 2022 21:34
c0617a5
to
e6a3e8b
Compare
Turns out you can pass both thus making mapping an ems `oid` to a brokerd-side `reqid` much more simple. This allows us to avoid keeping as much local dialog state but with still the following caveats: - ok `editOrder` msgs must update the reqid<->txid map - only pop `reqids2txids` entries inside the `cancelOrderStatus` handler
Why we need so many fields to accomplish passing through a dialog key to orders is beyond me but this is how they do it with edits.. Allows not having to handle `editOrderStatus` msgs to update the dialog key table and instead just do it in the `openOrders` sub by checking the canceled msg for a 'cancel_reason' of 'Order replaced', in which case we just pop the txid and wait for the new order the kraken backend engine will submit automatically, which will now have the correct 'userref' value we passed in via the `newuserref`, and then we add that new `txid` to our table.
Kill `pydantic` from `kraken`
Since we figured out how to pass through ems dialog ids to the `openOrders` sub we don't really need to do much with status updates other then error handling. This drops `process_status()` and moves the error handling logic into a status handler sub-block; we now just info-log status updates for troubleshooting purposes.
The (partial) fills from this sub are most indicative of clears (also says support) whereas the msgs in the `ownTrades` sub are only emitted after the entire order request has completed - there is no size-vlm remaining. Further enhancements: - this also includes proper subscription-syncing inside `subscribe()` with a small pre-msg-loop which waits on ack-msgs for each sub and raises any errors. This approach should probably be implemented for the data feed streams as well. - configure the `ownTrades` sub to not bother sending historical data on startup. - make the `openOrders` sub include rate limit counters. - handle the rare case where the ems is trying to cancel an order which was just edited and hasn't yet had it's new `txid` registered.
`kraken`: use `userref` field AND `reqid`, utilize `openOrders` sub for most msging
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
broker-backend
`brokerd`/`datad` related backend tech
clearing
auction and mm tech: EMS, OMS, algo-trading
perf
efficiency and latency optimization
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WS based order management with fixes for #310, #296 and hopefully most of #290.
Leverage the new 3.10
match:
syntax like crazy which turned out very nicely for making the msg loops way more grokableIncludes safeguard code to cancel all persistent orders found on startup until we get existing order loading working the EMS as per #293.
TODOs:
handle_order_updates()
{event: '[submit/edit/cancel]Orderstatus'}
blocks into a new sub-func?kraken
**live and dark** orders don't send correct fill messages, pp doesn't update... etc. #310kraken
**live and dark** orders don't send correct fill messages, pp doesn't update... etc. #310[ ] maybe we should delegate tosolved this for now using kraken's own asset info and pairs mapping tables.cryptofeed
for symbol normalization? bc kraken has a diff set for rest vs. ws apis.... (kill me)collections.ChainMap
to track thedict
-oriented flow of order dialogs on thekraken
api leg.Follow up (mostly pertaining to the wishlist in #345):
Position.size
logic?[ ] usingadded to Positioning system refinements: paper engine, file writing, toml style and perf #345 and will come in a follow up PR.piker.pp
immediate file updates, some we need to implement likely with thetrio
async file IO apis.userref
always being0
in theopenOrders
ep to kraken here: https://support.kraken.com/hc/en-us/requests/new?ticket_form_id=96688